<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/css/jilu.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
    <link rel="stylesheet" href="{{ layui.setter.base }}style/autoComplete.css">
</script>
<div class="box layui-fluid layui-row">
    <div class="form layui-form layui-col-sm12 layui-col-md12" lay-filter="app-content-comment">
        <div class="layui-form-item layui-col-sm2 layui-col-md2">
            <label class="layui-form-label">保养单号:</label>
            <div class="layui-input-block layui-col-space15">
                <input type="text" name="fil01" autocomplete="off" class="layui-input" list="student_one" id="ipt1">
                <datalist id="student_one"></datalist>
            </div>
        </div>
        <div class="layui-form-item layui-col-sm2 layui-col-md2">
            <label class="layui-form-label">设备编号：</label>
            <div class="layui-input-block">
                <input type="text" name="fil03" autocomplete="off " class="layui-input " id="ipt2" list="student_two">
                <datalist id="student_two"></datalist>
            </div>
        </div>
        <div class="layui-form-item layui-col-sm2 layui-col-md2 ">
            <label class="layui-form-label ">设备位置：</label>
            <div class="layui-input-block ">
                <input type="text" name="fil07" autocomplete="off " class="layui-input " id="ipt3" list="student_three">
                <datalist id="student_three"></datalist>
            </div>
        </div>
        <div class="layui-form-item layui-col-sm2 layui-col-md2 ">
            <label class="layui-form-label ">保养人员：</label>
            <div class="layui-input-block ">
                <input type="text" name="filuser" autocomplete="off " class="layui-input" id="ipt4" list="student_fore">
                <datalist id="student_fore"></datalist>
            </div>
        </div>
        <div class="layui-form-item layui-btn-container layui-col-sm2 layui-col-md2"
            style="display: flex;justify-content: flex-end; ">
            <button class="search-btn layui-btn layui-btn-radius layui-btn-primary" lay-submit
                lay-filter="LAY-app-content-comm">
                <i class="layui-icon layui-icon-search " style="font-size: 10px; color: #FFF;"></i>
                <span>查询</span>
            </button>
        </div>
    </div>
    <table class="layui-table" id="table" lay-filter="test"></table>
</div>
<script type="text/javascript">
    layui.use(['table', 'admin', 'laypage', 'laytpl', 'tree', 'form', 'api', 'view', 'laydate', 'utill'], function () {
        var $ = layui.$,
            admin = layui.admin,
            view = layui.view,
            api = layui.api,
            table = layui.table,
            setter = layui.setter,
            laytpl = layui.laytpl,
            utill = layui.utill,
            tree = layui.tree,
            laydate = layui.laydate,
            form = layui.form;
        var url = window.location.href;
        var lay = url.slice(url.lastIndexOf('#/')).split('#/')[1];
        sessionStorage.setItem('lay-this', JSON.stringify(lay));
        var type = 2;
        var cols = [[{
            type: 'checkbox',

        }, {
            type: 'numbers',
            title: '序号',

        }, {
            field: 'fil01',
            title: '工单编号',

        }, {
            field: 'fil03',
            title: '设备编号',

        }, {
            field: 'fia02',
            title: '设备名称',

        }, {
            field: 'fia05',
            title: '设备型号',

        }, {
            field: 'fil07',
            title: '设备位置',

        }, {
            field: 'fil14',
            title: '保养开始时间',

        }, {
            field: 'fil15',
            title: '保养完成时间',

        }, {
            field: 'tcReqDuration',
            title: '保养耗时',

        }, {
            field: 'filuser',
            title: '保养人员',

        }, {
            field: 'fil21',
            title: '描述',

        }, {
            field: 'tcHrSup',
            title: '验证人',

        },]
        ]; render();

        function render(data) {
            if (data == null) {
                var data = {
                    type: type
                }
            } else {
                var data = {
                    fil01: data.fil01,
                    fil03: data.fil03,
                    fil07: data.fil07,
                    filuser: data.filuser,
                    type: type,
                };
            }
            // 列定制
            utill.columnCustom('#table', "MtPlanRecordVO", {
                // 自己表格的接口
                url: api.host + api.maintain.Record1,
                where: data,
                checkbox: false
            });
        }

        utill.fuzzmatch("#ipt4", {
            isShowValue: true,
            reqObj: {
                url: api.host + api.maintain.ipt4,
                contentType: 'application/json',
                data: JSON.stringify({
                    filuser: '',
                    type: type
                }),
                type: 'POST'
            },
            dataTrans: function (res) {
                return res.data.map((item) => {
                    return {
                        label: item.GEN02,
                        value: item.TC_HR_GEN01,
                        data: item
                    }
                })
            }
        });
        form.render();

        form.on('submit(LAY-app-content-comm)', function (data) {
            var field = data.field;
            render(field)
        });
        table.on('row(test)', function (obj) {
            if (obj.data.fil05 == 2) $(this).attr('lay-href', `maintain/popup/create_work#?id=${obj.data.tcReqId}`);
            else $(this).attr('lay-href', `maintain/popup/keep#?id=${obj.data.tcReqId}`);
        });

    });
</script>